<?php

namespace App\Kuafu\CustomPayment\Validate;

use App\Kuafu\CustomPayment\Enum\CustomPaymentEnum;
use App\Kuafu\Base\Validate\BaseValidate;
use App\Kuafu\CustomPayment\Model\CustomPaymentModel;
use Illuminate\Support\Collection;
use Illuminate\Validation\Rule;

class CustomPaymentValidate extends BaseValidate
{

    /**
     * 获取规则信息
     *
     * @param array $fields
     * @return string[]
     */
    public static function getRules(array $fields = []): array
    {
        return self::getActuallyRules([
            'reckonType' => 'required|integer|in:' . implode(',', array_keys(CustomPaymentEnum::RECKON_TYPE_MAP)),
            'isInvoice'  => 'required|integer|in:' . implode(',', array_keys(CustomPaymentEnum::IS_INVOICE_MAP)),
            'type'       => 'required|integer|in:' . implode(',', array_keys(CustomPaymentEnum::TYPE_MAP)),
            'status'     => 'required|integer|in:' . implode(',', array_keys(CustomPaymentEnum::STATUS_MAP)),
            'name'       => [
                'required',
                'string',
                'max:255',
                Rule::unique(CustomPaymentModel::class)->where('isDeleted', 0)
            ],
            'id'         => ['required', Rule::exists(CustomPaymentModel::class)->where('isDeleted', 0)],
        ], $fields);
    }


    /**
     * 添加校验
     *
     * @param array $requestParams
     * @return array
     */
    public static function insertValidate(array $requestParams): array
    {
        return self::baseValidate(
            $requestParams,
            ['reckonType', 'isInvoice', 'type', 'name'],
            ['name.unique' => '自定义支付名称重复，请重新填写！']
        );
    }

    /**
     * 状态修改校验
     *
     * @param array $requestParams
     * @return array
     */
    public static function statusValidate(array $requestParams): array
    {
        return self::baseValidate($requestParams, ['status', 'id']);
    }

}
